<?php
/****
	队列执行文件
***/
/* 
	header('content-type:text/html;charset=utf-8');	
	ini_set('date.timezone','Asia/Shanghai');
	
	require_once $_SITE_PATH_ . "m/m_information.php";
	require_once $_SITE_PATH_ . "m/m_tasklist.php";
	require_once 'Queue_Class.php';
	require_once 'UpFile_ApiClient.class.php';
	
	$upfile_flag=isset($_POST['upfile_flag'])?$_POST['upfile_flag']:'';
	
	$m_information=new m_information();
	$m_tasklist=new m_tasklist();
	$queue=new QueueClass();
	
	$m_tasklist->_ssql='select `id`,`product_id` from tasklist where ts_type="1" and excuflag="0" and ts_flag="0" order by `id` ';//asc limit 0,1 
	$product_id=$m_tasklist->getArray($m_tasklist->query());
	$count=$m_tasklist->getCount(' ts_type="1" and excuflag="0" and ts_flag="0" ');
	 
	
	//var_dump($product_id);
	//exit;
	$code='';
	$code_str='';
	if($count<=0)
		{
			exit;
		}
		else
			{
				for($i=0;$i<$count;$i++)
					{
						$code=json_decode(trim($product_id[$i]->product_id,chr(231).chr(187).chr(191)),true);//解压JSON数据
						$order_sn='';
						//echo '<br/>';
						//var_dump($code);
						
						for($j=0;$j<count($code);$j++)
							{
								//$code_str.=','.$code['fileinfo'][$i]['code'];
								$order_sn=$code['order_sn'];
							}
						foreach($code as $key => $value)
							{
								if(strtolower($key)=='fileinfo')
									{
										$vcount=count($value);
										for($index=0;$index<$vcount;$index++)
											{
												$code_str.=','.$value[$i]['code'];
											}
									}
							}
							
						$code_str=trim($code_str,',');
						$product_id[$i]->code=$code_str;
						$product_id[$i]->order_sn=$order_sn;
						//echo $product_id[$i]->code;
						//echo '<br/>';
						$queue->add_item($product_id[$i]->code);//测试增加一个元素时的情况
					}
					
				for($i=0;$i<$count;$i++)
					{
						$code=$queue->del_item();
						$code=number_format($code,'','','');
						$auth='fileflag_task';
						$data=array('code'=>$code,'order_sn'=>$product_id[$i]->order_sn,'taskid'=>$product_id[$i]->id,'apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
						//var_dump($data);
						//echo '<br/>';
						//exit;
						$url='http://copr.hucai.com/index.php?a=apis.FileFlag_Client';
						//重新用计划任务执行指定次数的推送数据任务。
						$api=new UpFile_ApiClient();
						$result=$api->DoRequest($url,$auth,$data);
						var_dump($result);
						exit;
						usleep(100);
						 
					}
			}
			exit;
	 */	
	header('content-type:text/html;charset=utf-8');	
	ini_set('date.timezone','Asia/Shanghai');
	require_once 'E:\test1\sites\default\backend\apis/Queue_Class.php';
	require_once 'E:\test1\sites\default\backend\apis/UpFile_ApiClient.class.php';
	
	$queue=new QueueClass();
	$code='';
	$code_str='';
	$order_sn='';
	
	$auth='fileflag_code';
	$api=new UpFile_ApiClient();
	$data=array('code'=>$code,'order_sn'=>$order_sn,'taskid'=>'','apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
	$url='http://copr.hucai.com/?a=apis.FileFlag_Code';
	$result=$api->DoRequest($url,$auth,$data);
	//var_dump($result);
	//file_put_contents('code_value.txt',$result);
	
	if(get_magic_quotes_gpc())
		{
			stripslashes($result);
		}
	$result=json_decode(trim(urldecode($result),chr(239).chr(187).chr(191)),true);
	$count=count($result);
	//var_dump($result);
	//exit;
	
	if($count<=0 && empty($result))
		{
			exit;
		}
		else
			{
				for($i=0;$i<$count;$i++)
					{
						//var_dump($result[$i]['product_id']);
						$code=json_decode(trim($result[$i]['product_id'],chr(239).chr(187).chr(191)),true);//解压JSON数据
						
						//var_dump($code);
						$order_sn='';
						$order_sn=$code['order_sn'];
						for($j=0;$j<count($code['fileinfo']);$j++)
							{
								if(!empty($code['fileinfo'][$i])&& is_array($code['fileinfo'][$i]))
									{
										if(!empty($code['fileinfo'][$i]['code']))
											{
												$code_str.=','.number_format($code['fileinfo'][$i]['code'],'','','');
											}
										
									}
							}
						$code_str=trim($code_str,',');
						//echo $code_str;
						$queue->add_item($code_str);
					}
				
				for($i=0;$i<$count;$i++)
					{
						$cur=$queue->get_queue();
						//var_dump($cur);
						//exit;
						$code=$queue->del_item();
						$data=array('code'=>$code,'order_sn'=>$order_sn,'taskid'=>$result[$i]->id,'apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
						//var_dump($code);
						//file_put_contents('code_value.txt',$code);
						//var_dump($data);
						//exit;
						$url='http://copr.hucai.com/index.php?a=apis.FileFlag_Client';
						$result=$api->DoRequest($url,$auth,$data);
						echo '第 '.$i.' 条记录推送结果为：';
						var_dump($result);
						echo '<br/><br/>';
						exit;
						usleep(100);
					}
			}
			//var_dump($result);
			exit;	

?>